from flask import request,jsonify
import json




#无限极分类
def xtree(data):
    if data:
        tree = {}
        list = []
        #先抓换成字典
        for i in data:
            tree[i['id']] = i
        for j in data: 
            if j['pid'] == 0:
                list.append(j)
            else:
                if 'son' not in tree[j['pid']]:
                    tree[j['pid']]['son'] = []
                tree[j['pid']]['son'].append(j)
        
        return list

#获取数据
def get_data():
    data = request.data
    if data:
        data= json.loads(data)
    else:
        data = request.form
    
    return data

#七牛云
# 需要填写你的 Access Key 和 Secret Key
access_key = 'Z8cIpcbSFgFY7cu2pEROJAztVA2FZysEvW8cb6cT'
secret_key = 'RaYxEfA8-eJNe1ozvoquU17S-SXLS8pX-QayhB-L'


#容联云获取短信验证码
# #手机短信
from ronglian_sms_sdk import SmsSDK
accId = '8aaf07087bc82708017bf7aae5000e27'   #8aaf07087bc82708017bf7aae5000e27
accToken = 'f53d9d4740ed40adb6829538dc940709' #f53d9d4740ed40adb6829538dc940709
appId = '8aaf07087bc82708017bf7aae5e00e2e'  #8aaf07087bc82708017bf7aae5e00e2e
import json
def send_message(mobile,code,time):
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    mobile = mobile
    datas = (code, time)
    resp = sdk.sendMessage(tid, mobile, datas)
    result = json.loads(resp)
    if result['statusCode'] == '000000':
        return 1
    return 2





